import { defineConfig, loadEnv } from 'vite';
import createVitePlugins from './vite/index';
import { resolve } from 'path';

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
	const env = loadEnv(mode, process.cwd());
	const { VITE_APP_ENV } = env;
	return {
		base: VITE_APP_ENV === 'production' ? '/' : '/',
		plugins: createVitePlugins(command === 'build'),

		resolve: {
			alias: {
				'@': resolve(__dirname, './src'),
				'~': resolve(__dirname, './'),
			},
			extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
		},

		server: {
			port: 8080,
			host: true,
			open: true,
			proxy: {
				// '/api': {
				// 	target: 'http://localhost:8080',
				// 	changeOrigin: true,
				// 	rewrite: (path) => path.replace(/^\/api/, ''),
				// },
			},
			hmr: {
				overlay: false,
			},
		},
	};
});
